package b3.config
{
	
	public class Config
	{
		//分享信息
		public static var feedConfigs:Array;
		//视图信息
		public static var viewConfigs:Object;
		//小鸟信息
		public static var birdConfigs:Object;
		//城镇信息
		public static var townConfigs:Array;
		//建筑信息
		public static var buildingConfigs:Object;
		//吉尼斯信息
		public static var guinnessConfigs:Object;
		//比赛信息
		public static var matchConfigs:Object;
		//任务信息
		public static var taskConfigs:Object;
		//任务总数
		public static var taskNum:int;
		//称号数组 表 (以type 为索引   取出存放称号数组)
		public static var honourArrays:Object;
		//物品信息
		public static var objConfigs:Object;
		//状态信息
		public static var stateConfigs:Object;
		
		public function Config()
		{
		}
		
		public static function parseXML(dataXML:XML):void
		{
			//分享信息
			feedConfigs = new Array();
			for (var i:int = 0; i < dataXML.feedInfo.feed.length(); i++)
			{
				feedConfigs.push(new FeedConfig(dataXML.feedInfo.feed[i]));
			}
			//视图信息
			var obj:Object = new Object();
			viewConfigs = new Object();
			for (i = 0; i < dataXML.viewInfo.length(); i++)
			{
				var viewConfig:ViewConfig = new ViewConfig(dataXML.viewInfo[i]);
				viewConfigs[viewConfig.index] = viewConfig;
			}
			//小鸟信息
			birdConfigs = new Object();
			for (i = 0; i < dataXML.birdInfo.length(); i++)
			{
				var birdConfig:BirdConfig = new BirdConfig(dataXML.birdInfo[i]);
				birdConfigs[birdConfig.index] = birdConfig;
			}
			//解析建筑信息
			buildingConfigs = new Object();
			for (i = 0; i < dataXML.buildingInfo.building.length(); i++)
			{
				var buildingConfig:BuildingConfig = new BuildingConfig(dataXML.buildingInfo.building[i]);
				buildingConfigs[buildingConfig.index] = buildingConfig;
			}
			//解析吉尼斯信息
			guinnessConfigs = new Object();
			for (i = 0; i < dataXML.guinnessInfo.guinness.length(); i++)
			{
				var guinnessConfig:GuinnessConfig = new GuinnessConfig(dataXML.guinnessInfo.guinness[i]);
				guinnessConfigs[guinnessConfig.type + "_" + guinnessConfig.index] = guinnessConfig;
			}
			//解析比赛信息
			matchConfigs = new Object();
			for (i = 0; i < dataXML.matchInfo.match.length(); i++)
			{
				var matchConfig:MatchConfig = new MatchConfig(dataXML.matchInfo.match[i]);
				matchConfigs[matchConfig.index] = matchConfig;
			}
			//城镇信息
			townConfigs = new Array();
			for (i = 0; i < dataXML.mapLayer.length(); i++)
			{
				townConfigs.push(new TownConfig(dataXML.mapLayer[i]));
			}
			
			taskConfigs = new Object();
			taskNum = dataXML.taskInfo.task.length();
			var lastTaskConfig:TaskConfig;
			for (i = 0; i < dataXML.taskInfo.task.length(); i++)
			{
				var taskConfig:TaskConfig = new TaskConfig(dataXML.taskInfo.task[i]);
				
				taskConfig.index = i;
				taskConfigs[taskConfig.taskId] = taskConfig;
				
				if (lastTaskConfig != null)
				{
					lastTaskConfig.nextTaskId = taskConfig.taskId;
				}
				lastTaskConfig = taskConfig;
				if (i == dataXML.taskInfo.task.length() - 1)
					taskConfig.nextTaskId = -1;
			}
			
			//解析称号信息
			honourArrays = new Object();
			for (i = 0; i < dataXML.honourInfo.honour.length(); i++)
			{
				var honourConfig:HonourConfig = new HonourConfig(dataXML.honourInfo.honour[i]);
				var honourArr:Array = honourArrays[honourConfig.objectIndex];
				if (honourArr == null)
				{
					honourArr = new Array();
					honourArrays[honourConfig.objectIndex] = honourArr;
				}
				honourArr.push(honourConfig);
			}
			
			//解析物品信息
			objConfigs = new Object();
			for (i = 0; i < dataXML.objectInfo.object.length(); i++)
			{
				var objConfig:ObjConfig = new ObjConfig(dataXML.objectInfo.object[i]);
				objConfigs[objConfig.index] = objConfig;
			}
			//解析卡片信息
			for (i = 0; i < dataXML.cardInfo.card.length(); i++)
			{
				var cardConfig:CardConfig = new CardConfig(dataXML.cardInfo.card[i]);
				objConfigs[cardConfig.index] = cardConfig;
			}
			//解析许可证信息
			for (i = 0; i < dataXML.permitInfo.permit.length(); i++)
			{
				var permitConfig:ObjConfig = new PermitConfig(dataXML.permitInfo.permit[i]);
				objConfigs[permitConfig.index] = permitConfig;
			}
			//解析状态信息
			stateConfigs = new Object();
			for (i = 0; i < dataXML.stateInfo.state.length(); i++)
			{
				var stateConfig:StateConfig = new StateConfig(dataXML.stateInfo.state[i]);
				stateConfigs[stateConfig.index] = stateConfig;
			}
		}
		
		public static function getLevel(objectIndex:int, value:int):int
		{
			var level:int = 0;
			var honourArr:Array = honourArrays[objectIndex];
			for(var i:int = 0, len:int = honourArr.length; i< len; i++)
			{
				var honourConfig:HonourConfig = honourArr[i];
				if (value >= honourConfig.require)
				{
					level = i;
				}
				else
				{
					break;
				}
			}
			return level;
		}
	}
}